package com.qubuyer.repository.services

import com.qubuyer.core.http.HttpResult
import com.qubuyer.repository.entitys.*
import okhttp3.MediaType.Companion.toMediaType
import okhttp3.MultipartBody
import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import retrofit2.http.*

/**
 * Author: linwg
 * Time: 2021/2/2 0002
 * Description:
 */
interface ApiService {

    /**
     * 账号密码登录
     */
    @POST("user/login/appDoLogin")
    @FormUrlEncoded
    @Headers("NeedAuth:false")
    suspend fun login(
        @Field("username") username: String,
        @Field("password") password: String
    ): HttpResult<LoginEntity?>

    /**
     * 手机验证码登录
     */
    @POST("user/login/mobileDoLogin")
    @FormUrlEncoded
    @Headers("NeedAuth:false")
    suspend fun mobileLogin(
        @Field("username") username: String,
        @Field("code") code: String
    ): HttpResult<LoginEntity?>

    /**
     * 第三方登录
     */
    @POST("user/thirdLogin/login")
    @FormUrlEncoded
    @Headers("NeedAuth:false")
    suspend fun thirdPartLogin(
        @Field("oauth") oauth: String,
        @Field("openid") openid: String
    ): HttpResult<ThirdLoginEntity?>

    /**
     * 获取注册验证码
     */
    @POST("home/api/registerSms")
    @FormUrlEncoded
    @Headers("NeedAuth:false")
    suspend fun registerSms(@Field("mobile") mobile: String): HttpResult<String?>

    /**
     * 注册
     */
    @POST("User/login/doRegister")
    @FormUrlEncoded
    @Headers("NeedAuth:false")
    suspend fun doRegister(
        @Field("username") username: String,
        @Field("password") password: String,
        @Field("mobile_code") mobileCode: String,
        @Field("invitation_code") invitationCode: String
    ): HttpResult<LoginEntity?>

    /**
     * 获取找回密码验证码
     */
    @POST("home/api/verifySms")
    @FormUrlEncoded
    suspend fun verifySms(@Field("mobile") username: String): HttpResult<String?>

    /**
     * 提现申请
     */
    @POST("user/user/withdrawalApply")
    @FormUrlEncoded
    suspend fun withdrawalApply(
        @Field("money") money: String,
        @Field("oauth") oauth: String,
        @Field("mobile") mobile: String,
        @Field("code") code: String
    ): HttpResult<String?>

    /**
     * 更新用户手机第一步
     */
    @POST("user/user/setMobileOne")
    @FormUrlEncoded
    suspend fun setMobileOne(
        @Field("mobile") mobile: String,
        @Field("code") code: String
    ): HttpResult<String?>

    /**
     * 更新用户手机第二步
     */
    @POST("user/user/setMobileTwo")
    @FormUrlEncoded
    suspend fun setMobileTwo(
        @Field("mobile") mobile: String,
        @Field("code") code: String
    ): HttpResult<String?>

    /**
     * 第三方登录绑定手机号
     */
    @POST("user/thirdLogin/bind")
    @FormUrlEncoded
    suspend fun bind(
        @Field("mobile") mobile: String,
        @Field("code") code: String,
        @Field("oauth") oauth: String,
        @Field("openid") openid: String
    ): HttpResult<LoginEntity?>

    /**
     * 第三方登录设置密码
     */
    @POST("user/thirdLogin/setPassword")
    @FormUrlEncoded
    suspend fun setPassword(
        @Field("token") token: String,
        @Field("pushId") pushId: String = "S00330",
        @Field("password") password: String,
        @Field("password2") password2: String
    ): HttpResult<LoginEntity?>

    /**
     * 找回密码
     */
    @POST("user/login/forgetPassword")
    @FormUrlEncoded
    suspend fun forgetPassword(
        @Field("mobile") mobile: String,
        @Field("code") code: String,
        @Field("password") password: String,
        @Field("password2") password2: String
    ): HttpResult<String?>

    /**
     * 获取用户信息
     */
    @POST("user/user/userInfo")
    suspend fun userInfo(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<UserEntity?>

    /**
     * 获取用户消息数量
     */
    @POST("user/user/unSendNumber")
    suspend fun unSendNumber(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<UserMessageCountEntity?>

    /**
     * 退出登录
     */
    @POST("user/login/loginout")
    suspend fun logout(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<String?>

    /**
     * 获取首页banner
     */
    @POST("home/index/banner")
    suspend fun banner(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<HomeBannerEntity>?>

    /**
     * 获取首页分类
     */
    @POST("home/index/cate")
    suspend fun cate(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<HomeCategoryEntity>?>

    /**
     * 获取首页销售排行榜
     */
    @POST("home/index/distribut")
    suspend fun distribute(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<HomeSaleTopEntity?>

    /**
     * 获取首页超级返
     */
    @POST("home/index/returnGoods")
    suspend fun returnGoods(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<HomeGoodEntity>?>

    /**
     * 获取首页每日折扣
     */
    @POST("home/prom/discount")
    suspend fun discount(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<HomeGoodEntity>?>

    /**
     * 获取首页限时购
     */
    @POST("home/index/buyLimit")
    suspend fun buyLimit(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<HomeGoodEntity>?>

    /**
     * 获取抢购活动商品
     */
    @POST("home/prom/flashSale")
    suspend fun flashSale(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<HomeGoodEntity>?>

    /**
     * 获取首页热门推荐
     */
    @POST("home/index/isHot")
    suspend fun hotRecommend(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<HomeGoodEntity>?>

    /**
     * 获取首页推荐
     */
    @POST("home/index/goodsState")
    @FormUrlEncoded
    suspend fun homeRecommend(
        @Field("type") type: String? = null,
        @Field("limit") limit: String = "2"
    ): HttpResult<List<HomeGoodEntity>?>

    /**
     * 获取首页二级商品列表
     */
    @POST("home/goods/stateList")
    @FormUrlEncoded
    suspend fun stateList(
        @Field("page") page: Int,
        @Field("type") type: String
    ): HttpResult<List<HomeGoodEntity>?>


    /**
     * 获取二级分类商品列表
     */
    @POST("home/goods/goodsList")
    @FormUrlEncoded
    suspend fun goodsList(
        @Field("page") page: Int,
        @Field("pid") pid: String,
        @Field("cid") cid: String
    ): HttpResult<SecondCategoryGoodEntity?>

    /**
     * 获取分类列表
     */
    @POST("home/goods/cateList")
    suspend fun cateList(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<CategoryFirstEntity>?>

    /**
     * 获取购物车商品列表
     */
    @POST("home/cart/lists")
    suspend fun cartList(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<ShopCartGoodEntity>?>

    /**
     * 购物车商品删除
     */
    @POST("home/cart/del")
    @FormUrlEncoded
    suspend fun cartDel(@Field("id") id: String): HttpResult<String?>

    /**
     * 购物车商品收藏
     */
    @POST("user/user/goodsCollectSave")
    @FormUrlEncoded
    suspend fun cartCollect(@Field("id") id: String): HttpResult<String?>

    /**
     * 购物车商品数量调整
     */
    @POST("Home/cart/changeNum")
    @FormUrlEncoded
    suspend fun cartChangeNum(
        @Field("cart_id") cartId: String,
        @Field("goods_num") goodsNum: String
    ): HttpResult<String?>

    /**
     * 购物车商品单次选中
     */
    @POST("home/cart/radio")
    @FormUrlEncoded
    suspend fun cartGoodsCheck(@Field("id") id: String): HttpResult<String?>

    /**
     * 购物车商品单次取消选中
     */
    @POST("home/cart/unradio")
    @FormUrlEncoded
    suspend fun cartGoodsUnCheck(@Field("id") id: String): HttpResult<String?>

    /**
     * 购物车商品全选
     */
    @POST("home/cart/all")
    suspend fun cartGoodsAllCheck(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<String?>

    /**
     * 购物车商品取消全选
     */
    @POST("home/cart/unall")
    suspend fun cartGoodsAllUnCheck(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<String?>

    /**
     * 清空购物车失效商品
     */
    @POST("home/cart/delAll")
    @FormUrlEncoded
    suspend fun cartGoodsDelAll(@Field("id") id: String): HttpResult<String?>

    /**
     * 获取商品详情
     */
    @POST("home/goods/goodsInfo")
    @FormUrlEncoded
    suspend fun goodsInfo(@Field("id") id: String): HttpResult<HomeGoodEntity?>

    /**
     * 添加商品到购物车
     */
    @POST("home/cart/add")
    @FormUrlEncoded
    suspend fun cartAdd(
        @Field("goods_id") goodsId: String,
        @Field("goods_num") goodsNum: Int,
        @Field("item_id") itemId: String
    ): HttpResult<String?>

    /**
     * 获取商品评论列表
     */
    @POST("home/goods/goodsComment")
    @FormUrlEncoded
    suspend fun goodsComment(
        @Field("id") goodsId: String,
        @Field("type") type: Int
    ): HttpResult<List<GoodCommentEntity>?>

    /**
     * 获取我的评论列表
     */
    @POST("user/user/comment")
    suspend fun myComment(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<MineCommentEntity>?>

    /**
     * 获取商品评论评率
     */
    @POST("home/goods/goodsAssess")
    @FormUrlEncoded
    suspend fun goodsAssess(@Field("id") goodsId: String): HttpResult<GoodAssessEntity?>

    /**
     * 获取钱包信息
     */
    @POST("user/wallet/index")
    suspend fun walletInfo(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<WalletInfoEntity?>

    /**
     * 绑定三方账户
     */
    @POST("user/user/codeBind")
    @FormUrlEncoded
    suspend fun codeBind(
        @Field("oauth") oauth: String,
        @Field("openid") openid: String
    ): HttpResult<MineCardEntity?>

    /**
     * 获得支付宝授权链接
     */
    @POST("User/user/alipayInitApp")
    suspend fun alipayInitApp(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<String?>

    /**
     * 更新用户昵称
     */
    @POST("user/user/userInfoEdit")
    @FormUrlEncoded
    suspend fun userInfoEdit(@Field("nickname") nickname: String): HttpResult<String?>

    /**
     * 立即购买
     */
    @POST("User/cart/byNow")
    @FormUrlEncoded
    suspend fun buyNow(
        @Field("goods_num") goods_num: Int,
        @Field("goods_id") goods_id: Int,
        @Field("item_id") item_id: Int
    ): HttpResult<SOGoodInfoEntity?>

    /**
     * 立即购买下单
     */
    @POST("user/cart/buyNowPlace")
    @FormUrlEncoded
    suspend fun buyNowPlace(
        @Field("goods_num") goods_num: Int,
        @Field("goods_id") goods_id: Int,
        @Field("item_id") item_id: Int,
        @Field("address_id") address_id: String,
        @Field("invoice_type") invoice_type: String?,
        @Field("invoice_title") invoice_title: String?,
        @Field("invoice_taxpayer") invoice_taxpayer: String?,
        @Field("invoice_name") invoice_name: String?,
        @Field("invoice_email") invoice_email: String?,
        @Field("invoice_desc") invoice_desc: String?,
        @Field("user_note") user_note: String?,
        @Field("invoice_mobile") invoice_mobile: String?
    ): HttpResult<GoodSOResultEntity?>

    /**
     * 购物车购买
     */
    @POST("user/cart/cartPlace")
    @FormUrlEncoded
    suspend fun buyFromCartPlace(
        @Field("address_id") address_id: String,
        @Field("invoice_type") invoice_type: String?,
        @Field("invoice_title") invoice_title: String?,
        @Field("invoice_taxpayer") invoice_taxpayer: String?,
        @Field("invoice_name") invoice_name: String?,
        @Field("invoice_email") invoice_email: String?,
        @Field("invoice_desc") invoice_desc: String?,
        @Field("user_note") user_note: String?,
        @Field("invoice_mobile") invoice_mobile: String?
    ): HttpResult<GoodSOResultEntity?>

    /**
     * 购物车购买
     */
    @POST("User/cart/detail")
    suspend fun buyFromCart(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<SOGoodInfoEntity?>

    /**
     * 购物车购买
     */
    @POST("user/user/addressList")
    suspend fun addressList(@Body body: RequestBody = "{}".toRequestBody("application/json; charset=utf-8".toMediaType())): HttpResult<List<MineAddressEntity>?>

    /**
     * 订单金额计算
     */
    @POST("user/cart/priceCalculation")
    @FormUrlEncoded
    suspend fun priceCalculation(
        @Field("goods_num") goods_num: Int?,
        @Field("goods_id") goods_id: Int?,
        @Field("item_id") item_id: Int?,
        @Field("address_id") address_id: String
    ): HttpResult<CalcOrderPriceResultEntity?>

    /**
     * 获取微信支付参数
     */
    @POST("user/payment/wechatApp")
    @FormUrlEncoded
    suspend fun getWxPayParams(@Field("id") id: String): HttpResult<WechatPayParamEntity?>

    /**
     * 获取支付宝支付参数
     */
    @POST("user/payment/alipay")
    @FormUrlEncoded
    suspend fun getAliPayParams(@Field("id") id: String): HttpResult<String?>

    /**
     * 查询订单状态
     */
    @POST("user/payment/find")
    @FormUrlEncoded
    suspend fun getOrderStatus(@Field("id") id: String): HttpResult<PayResultEntity?>

    /**
     * 获取收支明细列表
     */
    @POST("user/user/detailed")
    @FormUrlEncoded
    suspend fun loadIncome(
        @Field("page") page: Int,
        @Field("type") type: String? = null,
        @Field("limit") limit: Int = 10
    ): HttpResult<List<IncomeEntity>?>

    /**
     * 获取折让订单列表
     */
    @POST("user/wallet/restore")
    @FormUrlEncoded
    suspend fun loadRebateOrderList(
        @Field("page") page: Int,
        @Field("type") type: Int,
        @Field("limit") limit: Int = 10
    ): HttpResult<List<RebateOrderEntity>?>

    /**
     * 获取活动消息列表
     */
    @POST("user/user/messageLinstActivity")
    @FormUrlEncoded
    suspend fun loadActiveMsgList(
        @Field("page") page: Int,
        @Field("limit") limit: Int = 10
    ): HttpResult<List<MessageEntity>?>

    /**
     * 获取系统消息列表
     */
    @POST("User/user/messageLinstSystem")
    @FormUrlEncoded
    suspend fun loadSysMsgList(
        @Field("page") page: Int,
        @Field("limit") limit: Int = 10
    ): HttpResult<List<MessageEntity>?>

    /**
     * 获取折让订单详情
     */
    @POST("user/wallet/restoreInfo")
    @FormUrlEncoded
    suspend fun loadRebateOrderDetail(
        @Field("id") page: Int
    ): HttpResult<RebateOrderEntity?>

    /**
     * 折让订单结算
     */
    @POST("user/wallet/restoreBalance")
    @FormUrlEncoded
    suspend fun restoreBalance(
        @Field("id") page: Int
    ): HttpResult<String?>

    /**
     * 获取销售总额列表
     */
    @POST("user/wallet/distribut")
    @FormUrlEncoded
    suspend fun loadSaleAmount(
        @Field("page") page: Int,
        @Field("type") type: Int,
        @Field("limit") limit: Int = 10
    ): HttpResult<SaleAmountEntity?>

    /**
     * 更新用户头像
     */
    @Multipart
    @POST("user/user/headImage")
    suspend fun updateHeadImage(@Part file: MultipartBody.Part): HttpResult<String?>
}